package com.hfkh.keyun.controller.backend;

import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.Major;
import com.hfkh.keyun.service.MajorService;
import com.hfkh.keyun.vo.MajorVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/major")
@Api(tags = "专业管理")
public class MajorController {

    @Resource
  private MajorService majorService;

    @PostMapping("/deleteMajor")
    @ApiOperation("按id删除专业列表")
    public ApiResult deleteMajor(@RequestBody Integer id){
        majorService.removeById(id);
        return ApiResult.ok("删除成功！", "头像上传成功！");
    }

    @PostMapping("/addMajor")
    @ApiOperation("添加专业列表")
    public ApiResult addMajor(@RequestBody MajorVO majorVO){
        Major major  = new Major();
        BeanUtils.copyProperties(majorVO,major);
         majorService.save(major);
         return ApiResult.ok("添加成功！", "头像上传成功！");
    }

    @GetMapping("/majorList")
    @ApiOperation("查询专业列表")
    public ApiResult<List<Major>> queryList(){
        Map<String ,Object> map=new HashMap<>();
        map.put("delete_flags",0);
        List<Major> carousels = majorService.listByMap(map);
        return ApiResult.success(carousels);
    }

    @PostMapping("/updateMajor")
    @ApiOperation("根据id修改专业列表")
    public ApiResult updateMajor(Integer id,MajorVO majorVO){
        Major major = new Major();
        BeanUtils.copyProperties(majorVO,major);
        major.setId(id);
        majorService.updateById(major);
        return ApiResult.ok("修改成功！", "头像上传成功！");
    }

}